<script type="text/javascript">
	$(document).ready(function(){
		var args = new Object();
		var data = ajax_call('userinfo', 'loginBonus', args, success_login_bonus);
	});
	function success_login_bonus(ret) {
		//今天是几号
		var now_day = ret.year+"-"+ret.month+"-"+ret.day;
		$(".now_day").html(now_day);
		var html = '<table>';
		html +='<tr><td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Tur</td><td>Fri</td><td>Sat</td></tr>';
		html +='<tr>';
		for ( var j=0; j<ret.start; j++ ) { 
			html +='<td>&nbsp</td>';
		}
		for ( var i=1; i<=ret.days; i++ ) {
			var bonus_class = Object();
			if( ret.sign_in_bonus==1 && ret.day==i ) {
				bonus_class.now = 'bonus_now_day';
			}
			var strI = i.toString();
			if (jQuery.inArray(strI, ret.sign_in_bonus_data) != -1 ) {
				bonus_class.selected = 'bonus_selected';
			}
			if ( jQuery.isEmptyObject(bonus_class) ) {
				html +='<td>'+i+'</td>';
			} else {
				html +='<td class="'+implode(' ',bonus_class)+'">'+i+'</td>';
			}
			if ( (i+2)%7==0 && i!=ret.days ) {
				html +='</tr><tr>';
			}
		}
		html +='</tr>';
		html += '</table>';
		$(".sign_in_bonus").html(html);
		if ( ret.sign_in_bonus==1 ) {
			$('.bonus_now_day').bind('click', function() {
			  	var args = new Object();
				var data = ajax_call('userinfo', 'signIn', args, success_sign_in);
			});
		}
		if ( ret.daily_bonus==1 ) {
			$("#daily_bonus_msg").html('<input type="button" id="get_daily_bonus" value="领取" />');
			$('#get_daily_bonus').bind('click', function() {
			  	var args = new Object();
				var data = ajax_call('userinfo', 'dailyBonus', args, success_daily_bonus);
			});
		} else {
			$("#daily_bonus_msg").html('已领取');
		}
	}
	
	function success_sign_in(ret) {
		$(".bonus_now_day").unbind("click");
		$(".bonus_now_day").removeClass("bonus_now_day").addClass("bonus_selected");
		var userinfo = Utils.getCookie("userinfo");
		userinfo = array_merge(userinfo, ret);
		Utils.setCookie("userinfo", userinfo);
		$("#header_coin").html(ret.coin);
		$("#header_cash").html(ret.cash);
		var args = Object();
		var alert_msg;
		if ( ret.get_coin!=0 || ret.get_cash!=0 ) {
			if ( ret.get_coin!=0 ) {
				args.get_coin = '获得游戏币:'+ret.get_coin;
			}
			if ( ret.get_cash!=0 ) {
				args.get_cash = '获得元宝:'+ret.get_cash;
			}
			alert_msg = implode(',',args);
		} else {
			alert_msg = '签到成功!';
		}
		alert(alert_msg);
	}
	
	function success_daily_bonus(ret) {
		var userinfo = Utils.getCookie("userinfo");
		userinfo = array_merge(userinfo, ret);
		Utils.setCookie("userinfo", userinfo);
		$("#header_coin").html(ret.coin);
		alert("获得游戏币"+ret.get_coin);
		$("#daily_bonus_msg").html('已领取');
	} 
</script>
<div class="now_day">
	
</div>
<div class="daily_bonus">
	领取每日奖励&nbsp;<span id="daily_bonus_msg"></span>
</div>
<div class="sign_in_bonus">
	
</div>
